package com.runa.protocol.dto;

public class DtuCMRequestData extends DtuRequestData implements IRequestData {

    public DtuCMRequestData(String dtuID, IRequestData requestData) {
        super(dtuID, requestData);
    }

    @Override
    public byte[] getData() {
        int length = requestData.getData().length;
        byte[] bytes = new byte[length * 2];
        int cnt = 0;
        for (int i=0; i<length; i++) {
            if (requestData.getData()[i] == (byte) 0xfd) {
                bytes[cnt++] = (byte) 0xfd;
                bytes[cnt++] = (byte) 0xed;
            } else if (requestData.getData()[i] == (byte) 0xfe) {
                bytes[cnt++] = (byte) 0xfd;
                bytes[cnt++] = (byte) 0xee;
            } else {
                bytes[cnt++] = requestData.getData()[i];
            }
        }
        byte[] emit = new byte[cnt];
        System.arraycopy(bytes, 0, emit, 0, cnt);
        return emit;
    }

}
